package com.deepbreath.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;

import com.deepbreath.entity.Position;

/**
 * 
 * @ClassName: Position
 * @Description: TODO(抓取城市站点信息)
 * @author wc
 * @date 2017年10月13日 上午11:30:20
 *
 */
public class Position extends Model<Position> {
	private static final long serialVersionUID = 1L;
	@TableId(type = IdType.INPUT)
	private String id;
	// 城市名称
	private String city;
	// 更新时间
	private Timestamp time;

	// 对健康影响情况
	private String affect;
	// 建议采取的措施
	private String action;
	// 数值单位
	@TableField("live_data_unit")
	private String liveDataUnit;

	// 监测站点名称
	@TableField("position_name")
	private String positionName;
	// AQI
	private Double aqi;
	// 空气质量(指数类别)
	private String quality;
	// 首要污染物
	@TableField("primary_pollutant")
	private String primaryPollutant;
	// PM2.5(细颗粒物)
	private Double pm25;
	// PM10(可吸入颗粒物)
	private Double pm10;
	// CO(一氧化碳)
	private Double co;
	// NO2(二氧化氮)
	private Double no2;
	// O3(臭氧1小时平均)
	private Double o3;
	// O3(臭氧8小时平均)
	private Double o38h;
	// SO2(二氧化硫)
	private Double so2;

	@Override
	protected Serializable pkVal() {
		return id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Timestamp getTime() {
		return time;
	}

	public void setTime(Timestamp time) {
		this.time = time;
	}

	public String getAffect() {
		return affect;
	}

	public void setAffect(String affect) {
		this.affect = affect;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getLiveDataUnit() {
		return liveDataUnit;
	}

	public void setLiveDataUnit(String liveDataUnit) {
		this.liveDataUnit = liveDataUnit;
	}

	public String getPositionName() {
		return positionName;
	}

	public void setPositionName(String positionName) {
		this.positionName = positionName;
	}

	public Double getAqi() {
		return aqi;
	}

	public void setAqi(Double aqi) {
		this.aqi = aqi;
	}

	public String getQuality() {
		return quality;
	}

	public void setQuality(String quality) {
		this.quality = quality;
	}

	public String getPrimaryPollutant() {
		return primaryPollutant;
	}

	public void setPrimaryPollutant(String primaryPollutant) {
		this.primaryPollutant = primaryPollutant;
	}

	public Double getPm25() {
		return pm25;
	}

	public void setPm25(Double pm25) {
		this.pm25 = pm25;
	}

	public Double getPm10() {
		return pm10;
	}

	public void setPm10(Double pm10) {
		this.pm10 = pm10;
	}

	public Double getCo() {
		return co;
	}

	public void setCo(Double co) {
		this.co = co;
	}

	public Double getNo2() {
		return no2;
	}

	public void setNo2(Double no2) {
		this.no2 = no2;
	}

	public Double getO3() {
		return o3;
	}

	public void setO3(Double o3) {
		this.o3 = o3;
	}

	public Double getO38h() {
		return o38h;
	}

	public void setO38h(Double o38h) {
		this.o38h = o38h;
	}

	public Double getSo2() {
		return so2;
	}

	public void setSo2(Double so2) {
		this.so2 = so2;
	}

	@Override
	public String toString() {
		return "Position [id=" + id + ", city=" + city + ", time=" + time + ", affect=" + affect + ", action=" + action
				+ ", liveDataUnit=" + liveDataUnit + ", positionName=" + positionName + ", aqi=" + aqi + ", quality="
				+ quality + ", primaryPollutant=" + primaryPollutant + ", pm25=" + pm25 + ", pm10=" + pm10 + ", co="
				+ co + ", no2=" + no2 + ", o3=" + o3 + ", o38h=" + o38h + ", so2=" + so2 + "]";
	}

	public Position() {
	}

	public static Double toDouble(String str, Double defaultValue) {
		if (str == null) {
			return defaultValue;
		}
		try {
			return Double.parseDouble(str);
		} catch (NumberFormatException nfe) {
			return defaultValue;
		}
	}

	public static Position build(List<String> datas) {
		Position position = new Position();
		position.positionName = datas.get(0);
		position.aqi = toDouble(datas.get(1), null);
		position.quality = datas.get(2);
		position.primaryPollutant = datas.get(3);
		position.pm25 = toDouble(datas.get(4), null);
		position.pm10 = toDouble(datas.get(5), null);
		position.co = toDouble(datas.get(6), null);
		position.no2 = toDouble(datas.get(7), null);
		position.o3 = toDouble(datas.get(8), null);
		position.o38h = toDouble(datas.get(9), null);
		position.so2 = toDouble(datas.get(10), null);

		return position;
	}
}
